/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers.utils;

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Anthares
 */
public class URLUtils {

    private static final Logger LOG = Logger.getLogger(URLUtils.class.getName());

    public static HashMap<String, String> getRequestedRessource(ServletContext ctx, HttpServletRequest req) {

        String[] requestUrl = getRequestedURI(req, ctx).replaceFirst("/", "").split("/");

        HashMap<String, String> result = new HashMap<String, String>();

        if (requestUrl.length > 0) {
            result.put("controller", requestUrl[0]);
        }
        if (requestUrl.length > 1) {
            result.put("action", requestUrl[1]);
        }

        return result;
    }

    public static String getRequestedURI(HttpServletRequest req, ServletContext ctx) {
        return req.getRequestURI().replace(ctx.getContextPath(), "");
    }
}
